HelperMethods = function(){};

// osigurava da su sva polja popunjena prije nego se dispatcha event
HelperMethods.isRecordValid = function(record) {
    for ( var key in record) {
        if (record.hasOwnProperty(key)) {
            var value =  record[key];
            if (record[key] == undefined || record[key] === '' ) {
                return false;
            }
        }
    }
    return true;
};

HelperMethods.roundNumber = function(number) {
    var numParts = new String(number).split('.');
    var roundedNumber = number;
    if (numParts.length == 2) {
        var tmpRoundValue = numParts[0];
        var tmpDecimalValue = new Number('0.' + numParts[1]);
        if (tmpDecimalValue > 0.5) {
            roundedNumber = new Number(tmpRoundValue) + 1;
        }
        else {
            roundedNumber = new Number(tmpRoundValue + '.5');
        }
    }
    return roundedNumber;
};

HelperMethods.numberRenderer = function(val, metadata, record, rowIndex, colIndex, store) {
    if (val && String(val).indexOf('.') > -1) {
        return Ext.util.Format.number(val, '0.000,00/i');
    }
    return Ext.util.Format.number(val, '0.000/i');

};

HelperMethods.isEmpty = function(obj) {
    for ( var prop in obj) {
        if (obj.hasOwnProperty(prop) && obj[prop].length > 0) {
            return false;
        }
    }
    return true;
};

HelperMethods.removeAllEventListeners = function(obj) {
  if(obj.items && obj.items.items) {
      HelperMethods.removeAllEventListeners(obj.items);
  }
  else if (obj.items) {
      for(var i = 0; i < obj.items.length; i++) {
          if(obj.items[i].items) {
              HelperMethods.removeAllEventListeners(obj.items[i].items);
          }
          obj.items[i].purgeListeners();
      }
  }
};

HelperMethods.getTime = function() {
  var date = new Date();
  return  '[' + date.format('d.m.Y H:i') + ']';
};

